﻿CREATE PROCEDURE [steve].[spSteve_UpdateUrlRewrite]
	@UrlRewriteId uniqueidentifier,
	@StartDate datetime2(7),
	@EndDate datetime2(7),
	@IsSecure bit,
	@RewriteOrder int,
	@IgnoreQueryString bit,
	@PassQueryString bit,
	@SiteUrlId uniqueidentifier,
	@RevisionDate datetime2(7),
	@RevisionMembershipId uniqueidentifier,
	@RevisionComment nvarchar(400)
AS
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	
	DECLARE @revision INT
	
	SELECT @revision = MAX(RevisionNumber) + 1
	FROM UrlRewriteRevision
	WHERE UrlRewriteId = @UrlRewriteId

	INSERT INTO UrlRewriteRevision (
		UrlRewriteId,
		RevisionNumber,
		StartDate,
		EndDate,
		IsSecure,
		RewriteOrder,
		IgnoreQueryString,
		PassQueryString,
		SiteUrlId,
		RevisionComment,
		RevisionDate,
		RevisionMembershipId)
	VALUES (
		@UrlRewriteId,
		@revision,
		@StartDate,
		@EndDate,
		@IsSecure,
		@RewriteOrder,
		@IgnoreQueryString,
		@PassQueryString,
		@SiteUrlId,
		@RevisionComment,
		@RevisionDate,
		@RevisionMembershipId)

	UPDATE UrlRewrite 
	SET LatestRevisionNumber = @revision 
	WHERE UrlRewriteId = @UrlRewriteId

	SELECT @revision as LatestRevisionNumber